package com.sdyeda.readiot;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;

import com.sdyeda.readiot.api.CallApi;
import com.sdyeda.readiot.fx.MainWindow;
import com.sdyeda.readiot.fx.Tray;
import com.sdyeda.readiot.tools.HexTools;

import javafx.application.Application;
import javafx.application.Platform;
import javafx.stage.Stage;

@SpringBootApplication
public class ReadIotApplication extends Application  {

	public static Stage primaryStage;
	public static ConfigurableApplicationContext springContext;
	
	public static void main(String[] args) {
		//tray.Init();
		new Tray();
		
		//生成注册码
		//1.根据注册信息机器编码，到期时间生成如下字符串（注意书写错误）： "sn:1909027001387 validtime:2099-12-31";
		//2.生成的字符串即为注册码，建议把末尾的多个=去掉（如果有）
		//3.生成License.lic 文件，内容只有该注册码，放于执行目录（jar或exe）即可
		//4.（不建议）也可在application.properties中增加 com.sdyeda.readiot.license=注册码
		
		/*  写项目，生成注册码
		String code = "sn:1909027001387 validtime:2099-12-31";

		String encrypt = DESUtil.getEncryptString(code);
		String decrypt = DESUtil.getDecryptString(encrypt);
		System.out.println("代码：" + code);
		System.out.println("注册码：" + encrypt);
		System.out.println("解码：" + decrypt);
		*/
		
		byte[] a = CallApi.MakeSender("/home/defly/iot-api-0.0.1.jar", "com.sdyeda.iotapi.IotYanyi","0000000000000000");		
		if(a!=null)
		System.out.print( HexTools.bytesToHex(a));
        
		launch(ReadIotApplication.class,args);
	}
	
	@Override
	public void init() throws Exception {
		//解决无法使用 @Component 问题
		springContext = SpringApplication.run(ReadIotApplication.class);
	}

	@Override
	public void start(Stage primaryStage) throws Exception {

		Platform.setImplicitExit(false);
		ReadIotApplication.primaryStage = primaryStage;
		new MainWindow();
	}
	

}
